package cn.pxs.controller;

import cn.pxs.entity.BlogsAndContent;
import cn.pxs.service.BlogsService;
import cn.pxs.tools.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/api/blogs")
public class BlogsController {
    @Autowired
    BlogsService blogsService;


    @RequestMapping("/findByTypeIdAndUid/{typeid}")
    @ResponseBody
    public Map findByTypeIdAndUid(@PathVariable("typeid")String typeid){
        return Tools.RespJson(200,"",blogsService.findByTypeIdAndUid(typeid,Tools.getUser().getId()));
    }

    @RequestMapping("/goAdd")
    public String goAdd(){
        return "blogs/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public Map add(@RequestBody Map map){
//        System.out.println(map);
        blogsService.add(map);
        return Tools.RespJson(200,"",null);
    }


    @RequestMapping("/delById/{id}")
    @ResponseBody
    public Map delById(@PathVariable("id") String id){
        blogsService.delById(id);
        return Tools.RespJson(200,"",blogsService.findByUid(Tools.getUser().getId()));
    }

    @RequestMapping("findByUid")
    @ResponseBody
    public Map findByUid(){
        return Tools.RespJson(200,"",blogsService.findByUid(Tools.getUser().getId()));
    }



}
